export default {
    componentUpdated(el, binding, vnode) {
        const ctx = vnode.context;
        if (!ctx || typeof ctx[binding.arg] === 'undefined' || ctx.autoHeightResizeListenner) return;
        ctx.autoHeightResizeListenner = () => {
            let top = el.offsetTop;
            let cur = el.offsetParent;
            while(cur !== null) {
                top += cur.offsetTop;
                cur = cur.offsetParent;
            }
            const h = (window.innerHeight - top - 50) + binding.value;
            ctx[binding.arg] = Math.max(h, 100);
        };
        window.addEventListener('resize', ctx.autoHeightResizeListener, false);
        ctx.$nextTick(()=>{
            ctx.autoHeightResizeListenner();
        })
    },
    unbind(el, binding, vnode){
        const ctx = vnode.context;
        if(ctx && ctx.autoHeightResizeListener) {
            window.removeEventListener('resize', ctx.autoHeightResizeListener, false);
            ctx.autoHeightResizeListener = null;
        }
    },
};